package com.wanmait.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.employment.entity.JobExperience;
import com.wanmait.employment.entity.ProjectExperience;
import com.wanmait.employment.entity.Userinfo;
import com.wanmait.employment.mapper.ProjectExperienceMapper;
import com.wanmait.employment.mapper.UserinfoMapper;
import com.wanmait.employment.service.ProjectExperienceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProjectExperienceServiceImpl implements ProjectExperienceService {
    @Resource
    private ProjectExperienceMapper projectExperienceMapper;

    @Resource
    private UserinfoMapper userinfoMapper;

    @Override
    public PageInfo<ProjectExperience> selectList(String title,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<ProjectExperience> projectExperienceQueryWrapper = new QueryWrapper<>();
        projectExperienceQueryWrapper.like("title",title).or().like("content",title).or().like("duty",title);
        List<ProjectExperience> projectExperienceList = projectExperienceMapper.selectList(projectExperienceQueryWrapper);
        PageInfo<ProjectExperience> projectExperiencePageInfo = new PageInfo<>(projectExperienceList);
        projectExperiencePageInfo.getList().forEach(projectExperience -> {
            QueryWrapper<Userinfo> userinfoQueryWrapper = new QueryWrapper<>();
            userinfoQueryWrapper.eq("id",projectExperience.getUserinfoId());
            Userinfo userinfo = userinfoMapper.selectOne(userinfoQueryWrapper);
            projectExperience.setUserinfo(userinfo);
        });
        return projectExperiencePageInfo;
    }

//    @Override
//    public void update(ProjectExperience projectExperience) {
//        projectExperienceMapper.updateById(projectExperience);
//    }

//    @Override
//    public Boolean insert(ProjectExperience projectExperience) {
//        LambdaQueryWrapper<ProjectExperience> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(ProjectExperience::getTitle,projectExperience.getTitle());
//        ProjectExperience projectExperience1 = projectExperienceMapper.selectOne(wrapper);
//        if(projectExperience1==null){
//            projectExperience.setUserinfoId(1);
//            projectExperienceMapper.insert(projectExperience);
//            return true;
//        }
//        else{
//            return false;
//        }
//    }

    @Override
    public void delete(Integer id) {
        projectExperienceMapper.deleteById(id);
    }

    @Override
    public List<ProjectExperience> selectId(Integer userinfoId) {
        QueryWrapper<ProjectExperience> projectExperienceQueryWrapper=new QueryWrapper<>();
        projectExperienceQueryWrapper.eq("userinfo_id",userinfoId);
        List<ProjectExperience> projectExperienceList=projectExperienceMapper.selectList(projectExperienceQueryWrapper);
        return projectExperienceList;
    }

    //    @Resource
//    private UserinfoMapper userinfoMapper;


}
